<%@ page language="java" import="java.util.*,com.hs.auth.model.*,com.hs.core.utils.*" pageEncoding="utf-8"%>
<%
HsAccount accObj = (HsAccount)request.getAttribute("accObj");
HsUserinfo userinfo = accObj==null?null:accObj.getUserinfo(); 
String flag = (String)request.getAttribute("flag");
List orgList = (List)request.getAttribute("orgList");
List roleList = (List)request.getAttribute("roleList");
String userrole = (String)request.getAttribute("userrole");
HsOrg org = (HsOrg)request.getAttribute("orginfo");
if(null == userrole){
	userrole="";
}
String status = "";
if(null != accObj){
	status = String.valueOf(accObj.getStatus());
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<title></title>
<%@ include file="../include.jsp"%>   
<script language="javascript" type="text/javascript" src="<%=path %>/thirtpart/My97DatePicker/WdatePicker.js"></script>

<style>.tac{text-align:center}</style>
 <script language="javascript" type="text/javascript">
 
 var flag = true;
 function callBackForCheckId(message){
 	  
 	    if("0" == message)
 	       alert("此帐号可以使用");
 	    else{
 	       alert("此帐号已存在，不可注册");  
 	    } 
 }
  function callBackForCheckId1(message){
 	  
 	    if("0" != message) {
 	       alert("此帐号已存在，不可注册"); 
 	       flag =false;
 	    } 
 }
 
 function checkUserId(){
 	 var logid = userform.loginid.value;
     if(isNull(logid)){
		        	alert("帐号不能为空!");
		            userform.loginid.focus();
		            return;
     }
     authdwr.isDouble(logid,callBackForCheckId);  
 
 }
 
 function saveData(){
            var logid = userform.loginid.value;
            var id = userform.id.value; 
             if(isNull(id)){
             	 if(isNull(logid)){
		        	alert("帐号不能为空!");
		            userform.loginid.focus();
		            return;
             	 }
              	 authdwr.isDouble(logid,callBackForCheckId1);   
             }
              setTimeout("checkform();",1000)
 	     
 
 }
 function checkform(){ 
    var logid = userform.loginid.value;
    var id = userform.id.value;
    var pwd = userform.pwd.value;
    var confirmpwd = userform.confirmpwd.value;
    var username = userform.username.value; 
    
    
     
    
        if(isNull(logid)){
        	alert("用户名不能为空!");
            userform.loginid.focus();
            return;
        }
        //alert(id);
       // alert(isNull(id));
        //新增用户时判断必须输入密码
        if(isNull(id)){
	        if(isNull(pwd)){
	        	alert("密码不能为空!");
	            userform.pwd.focus();
	            return;
	        }
        
	        if(isNull(confirmpwd)){
	        	alert("确认密码不能为空!");
	            userform.confirmpwd.focus();
	            return;
	        }
	        if( pwd != confirmpwd){
	        	alert("密码与确认密码不一致!");
	            userform.confirmpwd.focus();
	            return;
	        }
        }
        if(isNull(username)){
        	alert("用户姓名不能为空！");
            userform.username.focus();
            return;
        }
        
        
         //if(isNull(orgid)){
        //	alert("请选择所属单位！");
         //   userform.orgid.focus();
         //   return;
         //}
     
    if(flag)
 	  userform.submit(); 
 }

 </script>
</head>
<body class="cont_body">
<form name="userform" action="<%=basePath %>auth/saveUser.do" method="post">
    <table border="0" cellspacing="0" cellpadding="0" class="new"> 
      
      <caption>用户帐号信息(红色<font color=red>*</font>为必填项)</caption> 
       
      <tr>
        <td width="15%">帐号</td>
        <td  colspan=3 nowrap><input type="text" name="loginid" value="<%=accObj==null?"":accObj.getLoginid()==null?"":accObj.getLoginid() %>" style="width:65%" <%if(null != accObj && null != accObj.getLoginid()){out.print(" disabled");} %>/><font color=red><strong>*</strong></font>
         <input type="hidden" name="id" value="<%=accObj==null?"":accObj.getId() %>"  />
         <input type="hidden" name="userid" value="<%=userinfo==null?"":userinfo.getId() %>"  />
        <input type="button" value="用户名检测" onclick="checkUserId();"/>
        </td> 
      </tr>
       <tr>
        <td width="15%">密码</td>
        <td width="35%"><input type="password" name="pwd" value="" style="width:90%"></td>
        <td width="15%">确认密码</td>
        <td width="35%"><input type="password" name="confirmpwd" value="" style="width:90%"></td>
      </tr>
      
      
      <tr>
        <td width="15%">姓名</td>
        <td width="35%"><input type="text" name="username" value="<%=userinfo == null?"":userinfo.getUsername() %>" style="width:90%"><font color=red><strong>*</strong></font></td>
          <td width="15%">职称</td>
        <td width="35%">
         <%=DictCacheUtil.getInst().selectStrWithDefault("zhicheng","width:90%",userinfo==null?null:(userinfo.getZhicheng())+"","9") %><font color=red> </font>
       </td>  
      </tr>
       <tr>
        <td width="15%">出生年月</td>
        <td width="35%"><input type="text" class="Wdate" id="shengri" value="<%=userinfo == null?"":userinfo.getBirthday() ==null?"":userinfo.getBirthday()  %>" style="width:90%" name="shengri"  onFocus="WdatePicker({el:'shengri',dateFmt:'yyyy-MM-dd'})"  /></td>
        <td width="15%">性别</td>
        <td width="35%"><input type="radio" value='1' name="sex" <%if("1".equals(userinfo == null?"":(userinfo.getUsersex()+""))){ out.print(" checked");} %>/>男
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" value='2' name="sex" <%if("2".equals(userinfo == null?"":(userinfo.getUsersex()+""))){ out.print(" checked");} %>/>女</td>
      </tr>
        
       
       <tr>
        <td width="15%">固定电话</td>
        <td width="35%"><input type="text" name="phone" value="<%=userinfo == null?"":StringUtilTool.NULL2Blank(userinfo.getPhone()) %>" style="width:90%"></td>
        <td width="15%">手机</td>
        <td width="35%"><input type="text" name="handphone" value="<%=userinfo == null?"":StringUtilTool.NULL2Blank(userinfo.getHandphone()) %>" style="width:90%"></td>
      </tr> 
       <tr>
        <td width="15%">通信地址</td>
        <td colspan=3><input type="text" name="postaddress" value="<%=userinfo == null?"":StringUtilTool.NULL2Blank(userinfo.getAddress()) %>" style="width:96%"></td> 
      </tr>
      <tr>
        <td width="15%">电子邮箱</td>
        <td  ><input type="text" name="email" value="<%=userinfo == null?"":StringUtilTool.NULL2Blank(userinfo.getEmail()) %>" style="width:90%"></td>
        <td width="15%">邮政编码</td>
        <td width="35%"><input type="text" name="postno" value="<%=userinfo == null?"":StringUtilTool.NULL2Blank(userinfo.getPostnum()) %>" style="width:90%"></td> 
      </tr>
       <tr>
        <td width="15%">人员角色</td>
        <td colspan=3>
        <select name="roleid" style="width:96%">
	    <% if(roleList != null){
	           
	          for(int i =0;i<roleList.size();i++){
	              HsRole roleObj = (HsRole)roleList.get(i);
	              Long roleId = roleObj.getId();
	              String roleName = roleObj.getRolename();
	               %>
	                <option value="<%=roleId %>" <%if(userrole.equals(roleId+"")){out.print("selected");}%>><%= roleName%></option>
	               <%
	          }
	    }
	     %>     
        </select></td>
        </tr>
          
      <tr>
        <td colspan=4 align="middle"> 
        	<input name="" type="button" value="保存" onclick="saveData();" class="butt2" />
        </td> 
      </tr> 
    </table>  
</form>
</body>
</html>
<script>
<%if(null!= flag){ %> 
    alert("保存成功！");
    window.parent.list.frameElement.src = window.parent.list.frameElement.src; 
<%}%>
</script>
